package com.easy.cms.material.controller;

import java.util.List;
import java.util.UUID;

import com.easy.cms.material.dto.OrderCreateDTO;
import com.easy.cms.material.model.OrderMain;
import com.easy.cms.material.model.OrderSub;
import com.easy.cms.material.service.OrderService;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
public class OrderController {
    private OrderService orderService;
    @PostMapping("/orders")
    public OrderMain createOrder(@Valid @RequestBody OrderCreateDTO orderCreateDTO) {


    }

    @GetMapping("/orders/{mainOrderNumber}")
    public OrderMain getOrderByMainNumber(@RequestParam String mainOrderNumber) {
        return orderService.getOrderByMainNumber(mainOrderNumber);
    }

    @GetMapping("/orders/{mainOrderNumber}/subOrders")
    public List<OrderSub> getSubOrdersByMainNumber(@RequestParam String mainOrderNumber) {
        return orderService.getSubOrdersByMainNumber(mainOrderNumber);
    }

    @GetMapping("/orders")
    public List<OrderMain> getOrderMainList() {
        return orderService.getOrderMainList();
    }


    private String generateOrderNumber() {
        // 结合时间戳和随机数生成唯一订单编号
        return System.currentTimeMillis() + "-" + UUID.randomUUID().toString();
    }
}